package com.example.demo.controller;



import com.example.demo.dto.CommentRequest;
import com.example.demo.dto.LikeRequest;
import com.example.demo.entity.Post;
import com.example.demo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/community/post")

public class PostController {


    @Autowired
    private PostService postService;

    @GetMapping("/{postId}")
    public Post getPostDetail(@PathVariable String postId) {
        return postService.getPostDetail(postId);
    }

    @PostMapping("create")
    public void createPost(@RequestBody Post post) {
        postService.createPost(post);
    }

    @PostMapping("/{postId}/like")
    public Post likePost(@PathVariable String postId, @RequestBody LikeRequest likeRequest) {
        boolean isLiked = likeRequest.isLiked();
        return postService.likePost(postId, isLiked);
    }

    @PostMapping("/{postId}/comment")
    public Post submitComment(@PathVariable String postId, @RequestBody CommentRequest commentRequest) {
        String userId = commentRequest.getUserId();
        String content = commentRequest.getContent();
        return postService.submitComment(postId, userId, content);
    }

    @GetMapping("/hot")
    public List<Post> getHotPosts() {
        return postService.getHotPosts();
    }

}